package kosta.model.member;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class MemberServiceImpl implements MemberService{
	@Resource(name="memberDaoImpl")
	private MemberDao memberDao;
	
	@Override
	public MemberVO login(MemberVO mvo) throws Exception {		
		return memberDao.login(mvo);
	}

	@Override
	public MemberVO idCheck(String id) throws Exception {
		return memberDao.idCheck(id);
	}

	@Override
	public void update(MemberVO mvo) throws Exception {
		memberDao.update(mvo);
	}

	@Override
	public void leaveMember(String id) throws Exception {
		memberDao.leaveMember(id);
	}

	@Override
	public void register(MemberVO mvo) throws Exception {
		memberDao.register(mvo);
	}

	@Override
	public List<TestVO> testList(int grade, String id) throws Exception {
		memberDao.minusPoint(id);
		memberDao.minusPoint(id);
		memberDao.minusPoint(id);
		memberDao.minusPoint(id);
		memberDao.minusPoint(id);
		return memberDao.testList(grade);
	}

	@Override
	public void gradeUp(MemberVO mvo) throws Exception {
		memberDao.gradeUp(mvo);
	}
		
	////////////Member관리//////
		
	@Override
	public List<MemberVO> getAllMember(String id) throws Exception {
	return memberDao.getAllMember(id);
	}
	
	@Override
	public List<MemberVO> findMemberByGrade(String id, String gradeValue) throws Exception{
	HashMap map=new HashMap();
	map.put("id",id);
	map.put("grade",gradeValue);
	return memberDao.findMemberByGrade(map);
	}
	
	@Override
	public void outMember(String id) throws Exception {
	memberDao.outMember(id);
	
	}
	///////////////Test관리///////////////
	
	@Override
	public List<TestVO> getAllTest(String question) throws Exception {
	return memberDao.getAllTest(question);
	}
	
	@Override
	public List<TestVO> gradeByTest(String grade, String question)
		throws Exception {
	HashMap map=new HashMap();
	map.put("grade",grade);
	map.put("question",question);
	return memberDao.gradeByTest(map);
	}
	
	@Override
	public void updateTest(TestVO tvo) throws Exception {
	memberDao.updateTest(tvo);
	}
	
	@Override
	public TestVO findByTest(int no) throws Exception {
	return memberDao.findByTest(no);
	}
	
	@Override
	public void removeTest(int no) throws Exception {
	memberDao.removeTest(no);
	
	}
	
	@Override
	public void insertTest(TestVO tvo) throws Exception {
	memberDao.insertTest(tvo);
	
	}
	
	/////// rank
	@Override
	public MemberVO myLankView(String id) throws Exception {
		return memberDao.myLankView(id);
	}

	@Override
	public MemberLankVO findByLankID(String id) throws Exception {
		return memberDao.findByLankID(id);
	}

	@Override
	public void insertMyLank(MemberVO mvo) throws Exception {
		HashMap map = new HashMap();
		map.put("id", mvo.getId());
		map.put("rankpoint", (mvo.getPoint()*3)+(6-mvo.getGrade())*100);
		memberDao.insertMyLank(map);
	}

	@Override
	public void updateMyLank(MemberVO mvo) throws Exception {
		HashMap map = new HashMap();
		map.put("id", mvo.getId());
		map.put("rankpoint", (mvo.getPoint()*3)+(6-mvo.getGrade())*100);
		System.out.println("updateMyLank-------" + map);
		memberDao.updateMyLank(map);
	}

	@Override
	public MemberLankVO findByLankIdCount(String id) throws Exception {
		return memberDao.findByLankIdCount(id);
	}
}
